<?php

/**
 * Class Account
 */
abstract class Account
{
    /**
     * validate 验证用户
     * @param string $account
     * @param string $password
     * @return bool
     */
    protected function validate(string $account, string $password) : bool
    {
        return $account === 'root' && $password === '123456';
    }
    
    /**
     * calculateInterest
     * @return float
     */
    abstract protected function calculateInterest() : float;
    
    /**
     * getUserInfoByAccount
     * @param string $account
     * @return array
     */
    protected function getUserInfoByAccount(string $account) : array
    {
        return [
            'account' => $account,
            'money'   => 10000,
            'age'     => 25
        ];
    }
    
    
    /**
     * display
     */
    public function display()
    {
        $account = 'root';
        if (!$this->validate($account, '123456')) {
            echo '验证错误!' . PHP_EOL;
            return;
        }
        
        $userInfo = $this->getUserInfoByAccount($account);
        echo '用户信息为:' . PHP_EOL;
        var_dump($userInfo);
        
        $interest = $this->calculateInterest();
        echo '利息为:' . $interest * $userInfo['money'] . PHP_EOL;
    }
}

/**
 * 活期账户
 * Class CurrentAccount
 */
class CurrentAccount extends Account
{
    
    /**
     * calculateInterest
     * @return float
     */
    protected function calculateInterest() : float
    {
        echo '按活期利率计算利息!' . PHP_EOL;
        
        return 0.01;
    }
}


/**
 * 定期账户
 * Class SavingAccount
 */
class SavingAccount extends Account
{
    
    /**
     * calculateInterest
     * @return float
     */
    protected function calculateInterest() : float
    {
        echo '按定期利率计算利息!' . PHP_EOL;
        
        return 0.035;
    }
}

$account = new SavingAccount();
$account->display();